package cn.qyd.timer;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author 邱运铎
 * @date 2024-04-01 22:17
 */
public class TimeDemo {
    public static void main(String[] args) {
        LocalTime currentTime = LocalTime.now();
        System.out.println(currentTime);
        LocalDate currentDate = LocalDate.now();
        System.out.println(currentDate);
        LocalDateTime currentDateTime = LocalDateTime.now();
        System.out.println(currentDateTime);
        LocalDateTime demo01 = LocalDateTime.parse("2021-01-12T12:12:12");
        System.out.println(demo01);
        System.out.println(demo01.atZone(ZoneId.systemDefault()));
        System.out.println(Date.from(currentDateTime.atZone(ZoneId.systemDefault()).toInstant()));
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println(currentDateTime.format(dateTimeFormatter));
        LocalDateTime nextDay = currentDateTime.plusDays(1);
        System.out.println(nextDay.format(dateTimeFormatter));
        Duration between = Duration.between(currentDateTime, nextDay);
        System.out.println(between.toDays());
        System.out.println(between.toHours());
        System.out.println(nextDay.isBefore(currentDateTime));
        System.out.println(currentDateTime.isBefore(nextDay));
        System.out.println(nextDay.isEqual(currentDateTime));
    }
}
